## poly.asm
## 
## Program to calculate to largest, smallest
##
## Register Use:
##  $1    base register address
##  $2    conditinal value
##  $3    array size
##  $4    x
##  $5    largest number
##  $6    smallest number

        .text
        .globl  main

main:
        lui   $1,0x1000     #Init base register
        lw    $3,8($1)      #Loads the Array Size
        lw    $5,12($1)     #Sets Largest number to first in the array
        lw    $6,12($1)     #Sets Smallest number to first in the array
loop:   addu  $3,$3,-1      #Array Size minus 1
        beq   $3,$0,end     #If Array Size equals zero, go to end
        lw    $4,12($1)     #Array offset of 12
        addiu $1,$1,4       #increments base register
        slt   $2,$5,$4      #If $4>$5 $2=1     
        bne   $2,$0,big     #if $2=1 goto big
        ori   $2,$0,0       #else, and clears conditinal number
        slt   $2,$4,$6      #If $4<$6 $2=1
        bne   $2,$0,small   #if $2=1 goto small
        sll   $0,$0,0       #nop
        j     loop
        sll   $0,$0,0       #nop
big:    j     loop         
        addu  $5,$0,$4      #Puts X into $5
small:  j     loop
        addu  $6,$0,$4      #Puts X into $6
end:    lui   $1,0x1000     #Re-initilize base register
        sw    $6,0($1)      #Store Smallest Number into Memory
        sw    $5,4($1)      #Store Largest Number into Memory

.data
minim: .word 0
maxim: .word 0
size:  .word 12
array: .word 23, -12, 0, -32, 52, 7, 8, 0, 23, -45, 14, 36